package rabbitMQ.workQueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import rabbitMQ.common.Common;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost(Common.HOST);
        factory.setPort(Common.PORT);
        factory.setVirtualHost(Common.VIRTUALHOST);
        factory.setUsername(Common.USERNAME);
        factory.setPassword(Common.PASSWORD);

        Connection connection = factory.newConnection();

        Channel channel = connection.createChannel();

        channel.queueDeclare(Common.WORK_QUEUE, true, false, false, null);
        for(int i = 0; i < 10; i++){
            String msg = Common.SIMPLE_MSG + i;
            channel.basicPublish("", Common.WORK_QUEUE, null, msg.getBytes(StandardCharsets.UTF_8));
        }
        channel.close();
        connection.close();

    }
}
